package com.day19.Copy;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class CopyFileDemo {
    public static void main(String[] args) {

    }
    private static void method2(){
        FileReader fr=null;
        FileWriter fw=null;
        try{
            fr=new FileReader("fr.txt");
            fw=new FileWriter("fw.txt");
            char[] chars=new char[1024];
            int len;
            while((len=fr.read(chars))!=-1){
                fw.write(chars,0,len);
            }
        }catch (IOException e){
            e.printStackTrace();
        }finally{
            if(fw!=null){
                try{
                    fw.close();
                }catch (IOException e){
                    e.printStackTrace();
                }
            }
            if(fr!=null){
                try{
                    fr.close();
                }catch (IOException e){
                    e.printStackTrace();
                }
            }
        }
    }
    private static void method1() throws IOException{
        FileReader fr=new FileReader("fr.txt");
        FileWriter fw=new FileWriter("fw.txt");
        char[] chars=new char[1024];
        int len;
        while((len=fr.read(chars))!=-1){
            fw.write(chars,0,len);
        }
        fw.close();
        fr.close();
    }
}
